import { ApiBaseUrl } from "./config";
import axios from "axios";

let token = '';

export async function post(path,msg){
    msg.token = token;
    console.log(msg);
    return axios.post(`${ApiBaseUrl}${path}`, msg);
}

export function updateToken(newToken){
    token = newToken;
}

export function login(username,password){
    return axios.post(`${ApiBaseUrl}/user/login`, {
        username,
        password
    });
}

export function logout(){
    //console.log("req logout:",token);
    return axios.post(`${ApiBaseUrl}/user/logout`, {
        token
    });
}

export function checkToken(){
    //console.log("req checkToken:",token);
    return axios.post(`${ApiBaseUrl}/user/checktoken`, {
        token
    });
}